Re: [Libvir] [PATCH] Linux-VServer support
by Daniel Hokka Zakrisson
This update has moved the interface name to
/domain/devices/interface/target/@dev.
> This is an XML dump from one of my guests:
> <domain type='vserver' id='40010'>
> <name>lenny</name>
> <uuid>19e12957-261a-5a06-d6d0-89917d6d439f</uuid>
> <memory>2048000</memory>
> <os>
> <hostname>lenny.test</hostname>
> <type arch='i686'>vserver</type>
> </os>
> <devices>
> <interface type='ethernet'>
> <ip prefix='24' address='192.168.20.4' />
> <target dev='dummy0'/>
> </interface>
> <interface type='ethernet'>
> <ip prefix='24' type='range'
> address='192.168.32.100' address2='192.168.32.200'/>
> <target dev='dummy0'/>
> </interface>
> <disk type='directory' device='directory'>
> <source directory='/vservers/lenny' type='auto'
options='defaults'/> <target directory='/'/>
> </disk>
> <disk type='directory' device='directory'>
> <source directory='/srv' type='ext3' options='bind,ro'/>
> <target directory='/srv'/>
> </disk>
> <disk type='block' device='directory'>
> <source dev='/dev/mapper/test' type='ext3' options='defaults'/>
<target directory='/mnt'/>
> </disk>
> </devices>
> </domain>
--
Daniel Hokka Zakrisson
16 years, 11 months
[Libvir] libvirt on OS X Leopard 10.5.1
by Schley Andrew Kutz
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I spent the weekend attempting to get libvirt working on OS X Leopard
10.5.1. I was able to get it to compile, but not connect to libvirtd
running on either my KVM or Xen servers. Here are the instructions for
getting it to compile:
1. Download libvirt-0.4.0 from the mirrors.
2. Use macports to install pkgconfig and gnutls
3. Configure your source:
./configure --without-xen --without-qemu
4. Replace instances of 'hyper' in qemu/remote_protocol.x with 'long'
and then follow the instructions on http://libvirt.org/windows.html to
regen XDR structures.
5. Edit '/usr/include/net/if.h' and add the following include:
#include <net/if_var.h>
#include <sys/types.h>
//
// EDIT: akutz
//
#include <sys/socket.h>
6. Create a symlink for 'malloc.h' so the libvirt source can find it:
sudo ln -s /usr/include/malloc/malloc.h /usr/include/malloc.h
7. Add a header to "src/remote_internal.c":
//
// EDIT: akutz
//
#include <sys/un.h>
8. The version-script parameter of ld is not portable to OS X. Edit
'src/Makefile':
#
# EDIT: akutz
#
#libvirt_la_LDFLAGS = -Wl,--version-script=$(srcdir)/
libvirt_sym.version \
# -version-info 4:0:4 \
# $(COVERAGE_CFLAGS:-f%=-Wc,-f%) \
libvirt_la_LDFLAGS = -Wl, \
-version-info 4:0:4 \
$(COVERAGE_CFLAGS:-f%=-Wc,-f%) \
9. Replace the distribution copy of libread.dylib with the one from
Macports or else you will get errors about missing symbols (thread
starts here http://www.mail-archive.com/macports-dev@lists.macosforge.org/msg00729.html)
:
sudo mv /usr/lib/libreadline.dylib /usr/lib/libreadline.dylib.dist
sudo ln -s /opt/local/lib/libreadline.dylib /usr/lib/libreadline.dylib
10. The sources should now build and install.
At this point any attempt to connect to a remote host results in the
thread dying and OS X catching the exception with the following report:
<beginReport>
Process: Python [57356]
Path: /System/Library/Frameworks/Python.framework/Versions/
2.5/Resources/Python.app/Contents/MacOS/Python
Identifier: Python
Version: ??? (???)
Code Type: X86 (Native)
Parent Process: bash [59098]
Date/Time: 2008-01-21 16:48:52.228 -0600
OS Version: Mac OS X 10.5.1 (9B18)
Report Version: 6
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000004
Crashed Thread: 0
Thread 0 Crashed:
0 libvirt.0.dylib 0x00412911 remoteAuthenticate +
1345 (remote_internal.c:3062)
1 libvirt.0.dylib 0x00414869 doRemoteOpen + 3593
(remote_internal.c:753)
2 libvirt.0.dylib 0x00415499 remoteOpen + 137
(remote_internal.c:860)
3 libvirt.0.dylib 0x00401438 do_open + 392 (libvirt.c:
579)
4 libvirtmod.so 0x000c0e06 libvirt_virConnectOpen +
102 (libvirt-py.c:1026)
5 org.python.python 0x0018d826 PyEval_EvalFrameEx + 17116
6 org.python.python 0x0018da08 PyEval_EvalFrameEx + 17598
7 org.python.python 0x0018f47b PyEval_EvalCodeEx + 1638
8 org.python.python 0x0018f568 PyEval_EvalCode + 87
9 org.python.python 0x001a6a0c PyErr_Display + 1896
10 org.python.python 0x001a7036 PyRun_FileExFlags + 135
11 org.python.python 0x001a89a2 PyRun_SimpleFileExFlags
+ 421
12 org.python.python 0x001b3c23 Py_Main + 3095
13 org.python.pythonapp 0x00001fca 0x1000 + 4042
Thread 0 crashed with X86 Thread State (32-bit):
eax: 0x00000000 ebx: 0x004123e1 ecx: 0xbfffe826 edx: 0x00000000
edi: 0x00000000 esi: 0xbfffe92c ebp: 0xbfffea48 esp: 0xbfffe860
ss: 0x0000001f efl: 0x00010202 eip: 0x00412911 cs: 0x00000017
ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037
cr2: 0x00000004
Binary Images:
0x1000 - 0x1ffe org.python.pythonapp 2.5.0 (2.5.0a0)
<a2ccf04a940c23b34c33d7fe108d773e> /System/Library/Frameworks/
Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python
0x49000 - 0x4bfff +libgpg-error.0.dylib ??? (???) /opt/local/
lib/libgpg-error.0.dylib
0xbb000 - 0xc2ff3 +libvirtmod.so ??? (???)
<20dea38de64927c9e8b50a1fa240e067> /usr/local/lib/python2.5/site-
packages/libvirtmod.so
0x118000 - 0x1e3ffb org.python.python 2.5 (2.5)
<9786e5d8790a594bb7b3cdcf9a9d0b49> /System/Library/Frameworks/
Python.framework/Versions/2.5/Python
0x2f0000 - 0x2f7ff3 +libintl.8.dylib ??? (???) /opt/local/lib/
libintl.8.dylib
0x400000 - 0x424fef +libvirt.0.dylib ??? (???)
<70af9029fa4c7accc04377f0f65c53ae> /usr/local/lib/libvirt.0.dylib
0x43b000 - 0x49bfff +libgnutls.26.dylib ??? (???) /opt/local/lib/
libgnutls.26.dylib
0x4b5000 - 0x4c2fe2 +libtasn1.3.dylib ??? (???) /opt/local/lib/
libtasn1.3.dylib
0x4c7000 - 0x528ff3 +libgcrypt.11.dylib ??? (???)
<76bad0ad90909bf99f422f8bbfd61124> /opt/local/lib/libgcrypt.11.dylib
0x540000 - 0x637ff0 +libiconv.2.dylib ??? (???) /opt/local/lib/
libiconv.2.dylib
0x644000 - 0x654ffd +libz.1.dylib ??? (???) /opt/local/lib/libz.
1.dylib
0x65f000 - 0x661ffc apop.so ??? (???)
<8e5cbfa49bbed80ed34f03e008e3e086> /usr/lib/sasl2/apop.so
0x665000 - 0x67dfe2 dhx.so ??? (???)
<0831cf2893deaa2b5525ea7bfda17404> /usr/lib/sasl2/dhx.so
0x68c000 - 0x694fff digestmd5WebDAV.so ??? (???)
<42e13c06e037f02eee71a43324169f62> /usr/lib/sasl2/digestmd5WebDAV.so
0x698000 - 0x69afff libanonymous.2.so ??? (???)
<161902c9ed78dce78b61125c7c155f0f> /usr/lib/sasl2/libanonymous.2.so
0x69e000 - 0x6a0ffc libcrammd5.2.so ??? (???)
<c917c89eefddcfcacf48c939c3af12aa> /usr/lib/sasl2/libcrammd5.2.so
0x6a4000 - 0x6adffb libdigestmd5.2.so ??? (???)
<c8595204acd0e7cb362b33d008693019> /usr/lib/sasl2/libdigestmd5.2.so
0x6b1000 - 0x6b5fff libgssapiv2.2.so ??? (???)
<a47ee23249e7c36aee418a6e7fd3a502> /usr/lib/sasl2/libgssapiv2.2.so
0x6bb000 - 0x6bdffc login.so ??? (???)
<03d28ec908a6ed9abee1b25fe87716ef> /usr/lib/sasl2/login.so
0x6c1000 - 0x6c8ffc libotp.2.so ??? (???)
<0b7c8cd165835331c586e49465ef1186> /usr/lib/sasl2/libotp.2.so
0x6d2000 - 0x6d4ffc libplain.2.so ??? (???)
<5992f1149ff6cc7fadafa2bfd4ecc00a> /usr/lib/sasl2/libplain.2.so
0x6d8000 - 0x6ddffc libpps.so ??? (???)
<ae02d7b23951bddb4db705b2d632c6ac> /usr/lib/sasl2/libpps.so
0x6e3000 - 0x6e6fff mschapv2.so ??? (???)
<8d5951f3d3a0565fd772ebec4d2054fb> /usr/lib/sasl2/mschapv2.so
0x6ea000 - 0x6ecffc shadow_auxprop.so ??? (???)
<5137115453406a92cf514b65046a6b28> /usr/lib/sasl2/shadow_auxprop.so
0x6f2000 - 0x6f4ffd smb_lm.so ??? (???)
<e9ad275441e15388bf580b1cdf55b430> /usr/lib/sasl2/smb_lm.so
0x6f8000 - 0x6faffc smb_nt.so ??? (???)
<a7144a88919b4aea313caf6c4e86353a> /usr/lib/sasl2/smb_nt.so
0x6fe000 - 0x701ff0 smb_ntlmv2.so ??? (???)
<ccfa6d0eafa992db95ad309e32c6d400> /usr/lib/sasl2/smb_ntlmv2.so
0x8fe00000 - 0x8fe2d883 dyld 95.3 (???)
<81592e798780564b5d46b988f7ee1a6a> /usr/lib/dyld
0x90d29000 - 0x90e5bfe7 com.apple.CoreFoundation 6.5 (476)
<8bfebc0dbad6fc33bea0fa00a1b9ec37> /System/Library/Frameworks/
CoreFoundation.framework/Versions/A/CoreFoundation
0x90e5c000 - 0x90e7aff3 com.apple.DirectoryService.Framework 3.5
(3.5) <899d8c9ee31b004a6ff73dab88982b1a> /System/Library/Frameworks/
DirectoryService.framework/Versions/A/DirectoryService
0x922a3000 - 0x92353fff edu.mit.Kerberos 6.0.11 (6.0.11)
<33c25789baedcd70a7e24881775dd9ad> /System/Library/Frameworks/
Kerberos.framework/Versions/A/Kerberos
0x9244f000 - 0x924acffb libstdc++.6.dylib ??? (???)
<04b812dcec670daa8b7d2852ab14be60> /usr/lib/libstdc++.6.dylib
0x92510000 - 0x926d9fef com.apple.security 5.0.1 (32736)
<8c9eda0fcc1d8a571543025ac900715f> /System/Library/Frameworks/
Security.framework/Versions/A/Security
0x92f62000 - 0x92f80fff libresolv.9.dylib ??? (???)
<54e6a08c2f108bdf5916fb483d51961b> /usr/lib/libresolv.9.dylib
0x93661000 - 0x9366fffd libz.1.dylib ??? (???)
<5ddd8539ae2ebfd8e7cc1c57525385c7> /usr/lib/libz.1.dylib
0x936a2000 - 0x93783ff7 libxml2.2.dylib ??? (???)
<450ec38b57fb46013847cce851001a2f> /usr/lib/libxml2.2.dylib
0x93d28000 - 0x93d2ffe9 libgcc_s.1.dylib ??? (???)
<f53c808e87d1184c0f9df63aef53ce0b> /usr/lib/libgcc_s.1.dylib
0x94a5b000 - 0x94b93ff7 libicucore.A.dylib ??? (???)
<afcea652ff2ec36885b2c81c57d06d4c> /usr/lib/libicucore.A.dylib
0x95a7f000 - 0x95b5efff libobjc.A.dylib ??? (???)
<5eda47fec2d0e7853b3506aa1fd2dafa> /usr/lib/libobjc.A.dylib
0x9631e000 - 0x963d0ffb libcrypto.0.9.7.dylib ??? (???)
<330b0e48e67faffc8c22dfc069ca7a47> /usr/lib/libcrypto.0.9.7.dylib
0x9642c000 - 0x9643bfff libsasl2.2.dylib ??? (???)
<b9e1ca0b6612e280b6cbea6df0eec5f6> /usr/lib/libsasl2.2.dylib
0x9643c000 - 0x96466fef libauto.dylib ??? (???)
<d468bc4a8a69343f1748c293db1b57fb> /usr/lib/libauto.dylib
0x96d8c000 - 0x96d8dfef libmathCommon.A.dylib ??? (???) /usr/lib/
system/libmathCommon.A.dylib
0x96d9a000 - 0x96ef4fe3 libSystem.B.dylib ??? (???)
<8ecc83dc0399be3946f7a46e88cf4bbb> /usr/lib/libSystem.B.dylib
0xfffe8000 - 0xfffebfff libobjc.A.dylib ??? (???) /usr/lib/
libobjc.A.dylib
0xffff0000 - 0xffff1780 libSystem.B.dylib ??? (???) /usr/lib/
libSystem.B.dylib
</beginReport>
Anyway, hopefully someone on the list can make heads or tails of why
this is not working on OS X. I sure would love to be able to use
libvirt instead of xenapi. Thanks!
- --
- -a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
iD8DBQFHlSG1Tg8lceyAqqQRAiD1AJ99NZC23AheQl36oGYU/mmjqILbtwCg07+i
/TT0j27cGU7krDDMk+hVX/k=
=P+Cg
-----END PGP SIGNATURE-----
16 years, 11 months
[Libvir] a vmware driver
by Schley Andrew Kutz
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Does anyone know if there is work being done on a VMware driver? If
not, I could write one. I'm about to release an application via
SearchServerVirtualization called ivi (Java Virtual Interface) that
uses the VI SDK and the XenApi (cannot get libvirt to work on my dev
platform - OS X) to enable management of both VMware VI3 boxes as well
as Xen boxes. I would love to move away from the XenApi to libvirt,
and even more so to extend libvirt to support the VI SDK.
- --
- -a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
iD8DBQFHlhhqTg8lceyAqqQRAlaQAKCCjfrmKMAZyXlEQUVKh9uF/OoTHwCgkpSm
dPni/xjrHwSMrDvPmAkgidA=
=QfY7
-----END PGP SIGNATURE-----
16 years, 11 months
Re: [Libvir] libvirt on OS X Leopard 10.5.1
by Richard W.M. Jones
Schley Andrew Kutz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>> Probably the simplest is to compile the RPC bindings which are
>> generated on Linux and supplied with libvirt in CVS and the tarball
>> (ie. remote_protocol.[ch]). We need to supply only the xdr_quad type
>> and a handful of 64 bit functions. I did the same thing for Windows
>> but in that case built my own version of a mini-XDR library with some
>> contributions from glibc. What we could do is bundle this mini-XDR
>> library with libvirt itself (or perhaps persuade gnulib to take it --
>> Jim?).
>
> I would try this, but as you can see from the thread, I've hit a wall
> running the autogen script in Linux. It cannot find a devhelp file...
Try Jim's suggestion.
As for an XDR library replacement, take a look at my hacked-togther XDR
replacement. I have no idea if it'll work on Mac OS X, but worth a try:
http://www.annexia.org/tmp/xdr-4.0-mingw5.tar.gz
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, 11 months
[Libvir] Libvirt windows compilation errors
by Gabriel Kaufmann
Hi,
I downloaded libvirt-0.4.0 sources and patched it with libvirt-windows-20071129-2.patch.
I followed all the instructions from http://libvirt.org/windows.html and experienced some compilation problems which
Caused me to make the following changes.
1- For some reason Cygwin does not configure correctly the winsock2 usage, so after running the configure
I had to go to the config.h file and manually comment out the HAVE_WINSOCK2 macro declaration.
2- On file src/remote_internal.c :
1- Rename gnutls_cipher_algorithm_t to gnutls_cipher_algorithm
2- Add #include <sys/un.h>
3- On file qemud/qemud.c :
4- Remove include : #include "getaddrinfo.h"
(It was conflicting the include from ../src/getaddrinfo.h )
5- On file src/remote.c :
1- Rename gnutls_cipher_algorithm_t to gnutls_cipher_algorithm
2- Add #include "../src/getaddrinfo.h"
6- On tests folder added -lintl flag to the LIBS variable
Best Regards,
Gabriel Kaufmann
Software Engineer
Gabriel.Kaufmann(a)ericom.com<mailto:Gabriel.Kaufmann@ericom.com>
Ericom Software
Tel (Dir): +972 2 591 1700 Ext 754
Tel (Main): +972 2 591 1700
http://www.ericom.com
Access Done Right
Empower Enterprise-Wide Access to Microsoft(r) Terminal Server, Virtual Desktops and Legacy Applications
16 years, 11 months
[Libvir] unnecessary "if-before-free" tests
by Jim Meyering
Hi Dan,
I noticed a few new unnecessary "if-before-free" tests:
src/storage_backend.c:2591: if (groups[j]) free(groups[j]);
src/storage_backend_iscsi.c: if (devpath) free(devpath);
src/storage_backend_iscsi.c: if (portal) free(portal);
src/storage_backend_iscsi.c: if (session) free(session);
FYI, this finds all the one-liners:
git grep -E 'if \(([^)]+)\) free *\(\1\)'
I had to think harder to get the 2-line occurrences:
perl -0ne '/\b(if \(([^)]+)\)\s+free *\(\2\))/sgm and print "$ARGV:$.: $1\n"'\
$(git ls-files)
or rather this, if you don't have a git repo handy:
perl -0ne '/\b(if \(([^)]+)\)\s+free *\(\2\))/sgm and print "$ARGV:$.: $1\n"'\
{src,tests,qemud,proxy}/*.[ch]
If no one objects, I'm going to remove them
and add a build-time test to ensure they stay gone.
------------------
gnulib/lib/getaddrinfo.c:2257: if (cur->ai_canonname) free (cur->ai_canonname)
gnulib/lib/printf-parse.c:2277: if (a->arg)
free (a->arg)
proxy/libvirt_proxy.c:2499: if (name)
free(name)
qemud/qemud.c:2529: if (client->saslUsername) free(client->saslUsername)
src/buf.c:2549: if (buf->content)
free(buf->content)
src/conf.c:2551: if (tmp->comment)
free(tmp->comment)
src/hash.c:2559: if (iter->name)
free(iter->name)
src/iptables.c:2562: if (rule->rule)
free(rule->rule)
src/libvirt.c:2566: if (ret->name) free (ret->name)
src/openvz_conf.c:2570: if (prop)
free(prop)
src/qemu_conf.c:2578: if (prop)
free(prop)
src/qemu_driver.c:2580: if (base) free (base)
src/remote_internal.c:2584: if (name) free (name)
src/storage_backend.c:2591: if (groups[j]) free(groups[j])
src/storage_backend_iscsi.c:2597: if (devpath) free(devpath)
src/storage_conf.c:2605: if (def->name)
free(def->name)
src/storage_driver.c:2607: if (base) free (base)
src/test.c:2609: if (name)
free(name)
src/virsh.c:2615: if (ctl->name)
free(ctl->name)
src/xen_internal.c:2617: if (new)
free(new)
src/xend_internal.c:2621: if (drvName)
free(drvName)
src/xm_internal.c:2623: if (vif)
free(vif)
src/xml.c:2625: if (str)
free(str)
src/xmlrpc.c:2627: if (value)
free(value)
tests/testutils.c:2739: if (ts)
free(ts)
tests/xencapstest.c:2784: if (actualxml)
free(actualxml)
tests/xmconfigtest.c:2804: if (gotxml)
free(gotxml)
16 years, 11 months
[Libvir] Repository for work-in-progress storage patches
by Daniel P. Berrange
Jim suggested that it might be useful for me to make a repository available
with my work-in-progress storage patches even if they're not ready to merge
just yet.
I work using a mercurial patch queue, which is basically a mercurial native
version of quilt.
The master HG repository is an automated sync of CVS -> HG:
http://hg.berrange.com/libraries/libvirt--devel
The patch queue which applies ontop of this repo is:
http://hg.berrange.com/libraries/libvirt--storage
To use this you would try the following
1. Make sure the 'mg' extension is enabled in $HOME/.hgrc. You should have:
$ cat $HOME/.hgrc
[extensions]
hgext.mq=
2. Clone both repos in one go:
hg qclone -p http://hg.berrange.com/libraries/libvirt--storage \
http://hg.berrange.com/libraries/libvirt--devel
3. The local 'libvirt-storage' directory now contains the master repo,
along with an embedded patch queue. You can view the patch queue:
$ hg qseries
ignore-rules
misc-connection-hash
misc-libvirt-debug
misc-virsh-read-all
misc-default-uri
job-api
job-virsh
job-test-thread-safety
job-test-driver
storage-public-api
storage-driver-api
storage-remote-protocol
storage-remote-driver
storage-virsh
storage-virsh-args
storage-driver
storage-examples
storage-backend-helpers
storage-backend-fs
storage-backend-loop
storage-backend-lvm
storage-backend-iscsi
storage-backend-disk
storage-python-api
misc-python-generator
4. And you can apply / remove patches to/from the working directory with
the 'hg qpush' and 'hg qpop' commands. 'hg qdiff' will show contents
of the patches
$ hg qpush
applying ignore-rules
Now at: ignore-rules
$ hg qpush
applying misc-connection-hash
Now at: misc-connection-hash
....etc
When I've tidying up a few loose ends in the next few days I'll post the
current series with proper descriptions of each patch
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 -=|
16 years, 11 months
[Libvir] [PATCH] Avoid "may be used uninitialized" warning.
by Jim Meyering
I've been seeing this on rawhide for a few days:
xmconfigtest.c:115: warning: 'old_priv' may be used uninitialized in this function
Here's a fix:
Avoid "may be used uninitialized" warning.
* tests/xmconfigtest.c (testCompareParseXML): Initialize "old_priv".
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
tests/xmconfigtest.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index d66b660..f49ca6c 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -51,7 +51,7 @@ static int testCompareParseXML(const char *xmcfg_rel, const char *xml_rel,
int ret = -1;
virConnectPtr conn;
int wrote = MAX_FILE;
- void *old_priv;
+ void *old_priv = NULL;
struct _xenUnifiedPrivate priv;
char xmcfg[PATH_MAX];
char xml[PATH_MAX];
--
1.5.4.rc4.1.g1895
16 years, 11 months
[Libvir] PATCH: Cleanup generator & force build fail on missing APIs
by Daniel P. Berrange
The python generator will happily ignore functions it can't handle and
pretend everything completed without error. This leads to the situation
where we add new APis to C library and no one ever notices that they
are missing from the python until months later. This requires that my
previous patch be applied first to implement the missing APIs we already
have :-)
This patch causes the generator to return a non-zero exit status if there
are any APIs marked as FAILED. It will also explicitly print out their
names so its clear what is missing. In doing this I added a bunch more
functions to the skip list - ones that we already manually wrote.
It also removes the manually written virCloseConnect/virDomainFree/
virNetworkFree C code, since the generated code is just fine.
Finally, it makes all manually written C functions static for consistency
generator.py | 50 ++++++++++++++++++++++------------
libvir.c | 85 ++++++-----------------------------------------------------
2 files changed, 43 insertions(+), 92 deletions(-)
Dan.
diff -r 842dc0869c87 python/generator.py
--- a/python/generator.py Sat Jan 19 14:54:24 2008 -0500
+++ b/python/generator.py Sat Jan 19 14:58:50 2008 -0500
@@ -212,7 +212,7 @@ skipped_modules = {
}
skipped_types = {
- 'int *': "usually a return type",
+# 'int *': "usually a return type",
}
#######################################################################
@@ -277,6 +277,8 @@ skip_impl = (
'virDomainLookupByUUID',
'virNetworkGetUUID',
'virNetworkLookupByUUID',
+ 'virDomainGetAutostart',
+ 'virNetworkGetAutostart',
'virDomainBlockStats',
'virDomainInterfaceStats',
'virNodeGetCellsFreeMemory',
@@ -287,18 +289,23 @@ skip_impl = (
'virDomainPinVcpu',
)
-def skip_function(name):
- if name == "virConnectClose":
- return 1
- if name == "virDomainFree":
- return 1
- if name == "virNetworkFree":
- return 1
- if name == "vshRunConsole":
- return 1
- if name == "virGetVersion":
- return 1
- return 0
+
+# These are functions which the generator skips completly - no python
+# or C code is generated. Generally should not be used for any more
+# functions than those already listed
+skip_function = (
+ 'virConnectListDomains', # Python API is called virConectListDomainsID for unknown reasons
+ 'virConnSetErrorFunc', # Not used in Python API XXX is this a bug ?
+ 'virResetError', # Not used in Python API XXX is this a bug ?
+ 'virConnectGetVersion', # Not used in Python API XXX is this a bug ?
+ 'virGetVersion', # Python C code is manually written
+ 'virSetErrorFunc', # Python API is called virRegisterErrorHandler for unknown reasons
+ 'virConnCopyLastError', # Python API is called virConnGetLastError instead
+ 'virCopyLastError', # Python API is called virGetLastError instead
+ 'virConnectOpenAuth', # Python C code is manually written
+ 'virDefaultErrorFunc', # Python virErrorFuncHandler impl calls this from C
+)
+
def print_function_wrapper(name, output, export, include):
global py_types
@@ -314,7 +321,7 @@ def print_function_wrapper(name, output,
if skipped_modules.has_key(file):
return 0
- if skip_function(name) == 1:
+ if name in skip_function:
return 0
if name in skip_impl:
# Don't delete the function entry in the caller.
@@ -527,12 +534,19 @@ def buildStubs():
export.close()
wrapper.close()
- print "Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap,
- failed, skipped);
+ print "Generated %d wrapper functions" % nb_wrap
+
print "Missing type converters: "
for type in unknown_types.keys():
print "%s:%d " % (type, len(unknown_types[type])),
print
+
+ for f in functions_failed:
+ print "ERROR: failed %s" % f
+
+ if failed > 0:
+ return -1
+ return 0
#######################################################################
#
@@ -1130,5 +1144,7 @@ def buildWrappers():
txt.close()
classes.close()
-buildStubs()
+if buildStubs() < 0:
+ sys.exit(1)
buildWrappers()
+sys.exit(0)
diff -r 842dc0869c87 python/libvir.c
--- a/python/libvir.c Sat Jan 19 14:54:24 2008 -0500
+++ b/python/libvir.c Sat Jan 19 14:58:50 2008 -0500
@@ -23,14 +23,6 @@ extern void initcygvirtmod(void);
extern void initcygvirtmod(void);
#endif
-PyObject *libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
-PyObject *libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
-PyObject *libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
-PyObject *libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
-PyObject * libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
-PyObject * libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
-PyObject * libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
-
/* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
is so common that we encapsulate it here. Now, each use is simply
return VIR_PY_NONE; */
@@ -42,7 +34,7 @@ PyObject * libvirt_virNodeGetCellsFreeMe
* *
************************************************************************/
-PyObject *
+static PyObject *
libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
virDomainPtr domain;
PyObject *pyobj_domain;
@@ -71,7 +63,7 @@ libvirt_virDomainBlockStats(PyObject *se
return(info);
}
-PyObject *
+static PyObject *
libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
virDomainPtr domain;
PyObject *pyobj_domain;
@@ -422,7 +414,7 @@ static PyObject *libvirt_virPythonErrorF
static PyObject *libvirt_virPythonErrorFuncHandler = NULL;
static PyObject *libvirt_virPythonErrorFuncCtxt = NULL;
-PyObject *
+static PyObject *
libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUTE_UNUSED)
{
virError err;
@@ -446,7 +438,7 @@ libvirt_virGetLastError(PyObject *self A
return info;
}
-PyObject *
+static PyObject *
libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
{
virError err;
@@ -714,41 +706,6 @@ libvirt_virGetVersion (PyObject *self AT
return Py_BuildValue ((char *) "kk", libVer, typeVer);
}
-static PyObject *
-libvirt_virDomainFree(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
- PyObject *py_retval;
- int c_retval;
- virDomainPtr domain;
- PyObject *pyobj_domain;
-
- if (!PyArg_ParseTuple(args, (char *)"O:virDomainFree", &pyobj_domain))
- return(NULL);
- domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
-
- LIBVIRT_BEGIN_ALLOW_THREADS;
- c_retval = virDomainFree(domain);
- LIBVIRT_END_ALLOW_THREADS;
- py_retval = libvirt_intWrap((int) c_retval);
- return(py_retval);
-}
-
-static PyObject *
-libvirt_virConnectClose(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
- PyObject *py_retval;
- int c_retval;
- virConnectPtr conn;
- PyObject *pyobj_conn;
-
- if (!PyArg_ParseTuple(args, (char *)"O:virConnectClose", &pyobj_conn))
- return(NULL);
- conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
-
- LIBVIRT_BEGIN_ALLOW_THREADS;
- c_retval = virConnectClose(conn);
- LIBVIRT_END_ALLOW_THREADS;
- py_retval = libvirt_intWrap((int) c_retval);
- return(py_retval);
-}
static PyObject *
libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
@@ -872,7 +829,7 @@ libvirt_virNodeGetInfo(PyObject *self AT
return(py_retval);
}
-PyObject *
+static PyObject *
libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval;
unsigned char uuid[VIR_UUID_BUFLEN];
@@ -917,25 +874,6 @@ libvirt_virDomainLookupByUUID(PyObject *
c_retval = virDomainLookupByUUID(conn, uuid);
LIBVIRT_END_ALLOW_THREADS;
py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
- return(py_retval);
-}
-
-
-static PyObject *
-libvirt_virNetworkFree(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
- PyObject *py_retval;
- int c_retval;
- virNetworkPtr domain;
- PyObject *pyobj_domain;
-
- if (!PyArg_ParseTuple(args, (char *)"O:virNetworkFree", &pyobj_domain))
- return(NULL);
- domain = (virNetworkPtr) PyvirNetwork_Get(pyobj_domain);
-
- LIBVIRT_BEGIN_ALLOW_THREADS;
- c_retval = virNetworkFree(domain);
- LIBVIRT_END_ALLOW_THREADS;
- py_retval = libvirt_intWrap((int) c_retval);
return(py_retval);
}
@@ -1024,7 +962,7 @@ libvirt_virConnectListDefinedNetworks(Py
}
-PyObject *
+static PyObject *
libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval;
unsigned char uuid[VIR_UUID_BUFLEN];
@@ -1073,7 +1011,7 @@ libvirt_virNetworkLookupByUUID(PyObject
}
-PyObject *
+static PyObject *
libvirt_virDomainGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval;
int c_retval, autostart;
@@ -1096,7 +1034,7 @@ libvirt_virDomainGetAutostart(PyObject *
}
-PyObject *
+static PyObject *
libvirt_virNetworkGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval;
int c_retval, autostart;
@@ -1118,8 +1056,8 @@ libvirt_virNetworkGetAutostart(PyObject
return(py_retval);
}
-PyObject * libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED,
- PyObject *args)
+static PyObject *
+libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
{
PyObject *py_retval;
PyObject *pyobj_conn;
@@ -1165,9 +1103,7 @@ static PyMethodDef libvirtMethods[] = {
static PyMethodDef libvirtMethods[] = {
#include "libvirt-export.c"
{(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL},
- {(char *) "virDomainFree", libvirt_virDomainFree, METH_VARARGS, NULL},
{(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL},
- {(char *) "virConnectClose", libvirt_virConnectClose, METH_VARARGS, NULL},
{(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
{(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL},
{(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL},
@@ -1177,7 +1113,6 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler, METH_VARARGS, NULL},
{(char *) "virGetLastError", libvirt_virGetLastError, METH_VARARGS, NULL},
{(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL},
- {(char *) "virNetworkFree", libvirt_virNetworkFree, METH_VARARGS, NULL},
{(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL},
{(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL},
{(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL},
--
|=- 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 -=|
16 years, 11 months
[Libvir] PATCH: Add missing APIs to python binding
by Daniel P. Berrange
The python binding is missing all the APIs relating to CPU pinning and
schedular parameters because they are too hard for the generator to manage.
This patch implements them manually. Now a few words about the impls since
they are non-trivial
* virDomainGetSchedulerType
The C binding has a return value, and an out parameter. I translated
this into a tuple in python (schedular-type, n-parms)
eg
print dom.schedulerType()
('credit', 2)
Arguably we could drop the nparams field - its less use in python
since you don't have to pre-allocate a virSchedParam list.
* virDomainGetSchedulerParameters
This has an out parameter which is a list of virSchedParam structs, and
a param specifying the length of the passed in virSchedParam list. The
latter is irrelevant; The former I translated into a hash table return
value
eg
print dom.schedulerParameters()
{'cap': 0, 'weight': 100}
* virDomainSetSchedulerParameters
This has two in parameters, a list of virSchedParma structs, and a param
specifying length of the list. I just convert this into a hash. I also
make all the fields optional - it'll copy existing values for any params
which are omimtted.
eg
dom.setSchedulerParameters({'weight': 100})
* virDomainGetVcpus
This has two out parameters, a list of virVcpuInfo structs, and a bitmap
both pre-allocated, and their size passed in. This needs to be turned into
a 2 element tuple return value. First element returning vcpu info, and the
second element returning mapping. The vcpu info will be returned as a list
of lists, and the cpumap will be another list of lists - a True indicating
affinity.
eg
(cpuinfo, cpumap) = dom.vcpus()
print cpuinfo
print cpumap
[(0, 2, 7753916026L, 1), (1, 2, 5698028782L, 0), (2, 2, 4916522979L, 0), (3, 2, 3773416711L, 1)]
[(False, True), (True, True), (True, False), (True, True)]
* virDomainPinVcpu
This takes a vcpu number and a bitmap of affinity. I turn the bitmap
into a list of True/False values
eg
dom.pinVcpu(1, (True, True))
The generator fails on the C code part of the bindings completely, so that
is hand-written. It also fails on the python part of the bindings, but
the way the generator is structured doesn't enable us to hand-write the
python part for methods within objects :-( So I have basically just editted
the generator to blacklist all the out-parameters, and blacklist the in
parameters which specify list lengths.
Here is the code I used to test the functions:
#!/usr/bin/python
import libvirt
con = libvirt.open("xen:///")
dom = con.lookupByName("rhel5pv")
dominfo = dom.info()
nodeinfo = con.getInfo()
pcpus = nodeinfo[4] * nodeinfo[5] * nodeinfo[6] * nodeinfo[7]
(cpuinfo, cpumap) = dom.vcpus()
print cpuinfo
print cpumap
for i in range(dominfo[3]):
print "vcpu: %d" % i
if cpuinfo[i][1] == 0:
print "state: offline"
elif cpuinfo[i][1] == 2:
print "state: blocked"
else:
print "state: running"
print "cputime: %d" % cpuinfo[i][2]
print "pcpu: %d" % cpuinfo[i][3]
affinity = ""
for p in range(pcpus):
if cpumap[i][p] == True:
affinity = affinity + "y"
else:
affinity = affinity + "-"
print "affinity: %s" % affinity
print
dom.pinVcpu(1, (True, True))
print dom.schedulerType()
print dom.schedulerParameters()
dom.setSchedulerParameters({"weight": 100})
And here is the diffstat:
generator.py | 26 ++++
libvir.c | 318 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 344 insertions(+)
Dan.
diff -r 8468c0d428c9 python/generator.py
--- a/python/generator.py Sun Jan 20 12:06:47 2008 -0500
+++ b/python/generator.py Sun Jan 20 12:07:59 2008 -0500
@@ -229,6 +229,7 @@ py_types = {
'double': ('d', None, "double", "double"),
'unsigned int': ('i', None, "int", "int"),
'unsigned long': ('l', None, "long", "long"),
+ 'unsigned long long': ('l', None, "longlong", "long long"),
'unsigned char *': ('z', None, "charPtr", "char *"),
'char *': ('z', None, "charPtr", "char *"),
'const char *': ('z', None, "charPtrConst", "const char *"),
@@ -279,6 +280,11 @@ skip_impl = (
'virDomainBlockStats',
'virDomainInterfaceStats',
'virNodeGetCellsFreeMemory',
+ 'virDomainGetSchedulerType',
+ 'virDomainGetSchedulerParameters',
+ 'virDomainSetSchedulerParameters',
+ 'virDomainGetVcpus',
+ 'virDomainPinVcpu',
)
def skip_function(name):
@@ -918,6 +924,16 @@ def buildWrappers():
txt.write(" %s()\n" % func);
n = 0
for arg in args:
+ if name == "virDomainPinVcpu" and arg[0] == "maplen":
+ continue
+ if name == "virDomainGetSchedulerType" and arg[0] == "nparams":
+ continue
+ if name == "virDomainSetSchedulerParameters" and arg[0] == "nparams":
+ continue
+ if name == "virDomainGetSchedulerParameters" and arg[0] != "domain":
+ continue
+ if name == "virDomainGetVcpus" and arg[0] != "domain":
+ continue
if n != index:
classes.write(", %s" % arg[0])
n = n + 1
@@ -939,6 +955,16 @@ def buildWrappers():
classes.write("libvirtmod.%s(" % name)
n = 0
for arg in args:
+ if name == "virDomainPinVcpu" and arg[0] == "maplen":
+ continue
+ if name == "virDomainGetSchedulerType" and arg[0] == "nparams":
+ continue
+ if name == "virDomainSetSchedulerParameters" and arg[0] == "nparams":
+ continue
+ if name == "virDomainGetSchedulerParameters" and arg[0] != "domain":
+ continue
+ if name == "virDomainGetVcpus" and arg[0] != "domain":
+ continue
if n != 0:
classes.write(", ");
if n != index:
diff -r 8468c0d428c9 python/libvir.c
--- a/python/libvir.c Sun Jan 20 12:06:47 2008 -0500
+++ b/python/libvir.c Sun Jan 20 12:07:59 2008 -0500
@@ -102,6 +102,319 @@ libvirt_virDomainInterfaceStats(PyObject
PyTuple_SetItem(info, 7, PyLong_FromLongLong(stats.tx_drop));
return(info);
}
+
+
+static PyObject *
+libvirt_virDomainGetSchedulerType(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
+ virDomainPtr domain;
+ PyObject *pyobj_domain, *info;
+ char *c_retval;
+ int nparams;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerType",
+ &pyobj_domain))
+ return(NULL);
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ c_retval = virDomainGetSchedulerType(domain, &nparams);
+ if (c_retval == NULL)
+ return VIR_PY_NONE;
+
+ /* convert to a Python tupple of long objects */
+ if ((info = PyTuple_New(2)) == NULL) {
+ free(c_retval);
+ return VIR_PY_NONE;
+ }
+
+ PyTuple_SetItem(info, 0, libvirt_constcharPtrWrap(c_retval));
+ PyTuple_SetItem(info, 1, PyInt_FromLong((long)nparams));
+ free(c_retval);
+ return(info);
+}
+
+static PyObject *
+libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
+ virDomainPtr domain;
+ PyObject *pyobj_domain, *info;
+ char *c_retval;
+ int nparams, i;
+ virSchedParameterPtr params;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerParameters",
+ &pyobj_domain))
+ return(NULL);
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ c_retval = virDomainGetSchedulerType(domain, &nparams);
+ if (c_retval == NULL)
+ return VIR_PY_NONE;
+ free(c_retval);
+
+ if ((params = malloc(sizeof(*params)*nparams)) == NULL)
+ return VIR_PY_NONE;
+
+ if (virDomainGetSchedulerParameters(domain, params, &nparams) < 0) {
+ free(params);
+ return VIR_PY_NONE;
+ }
+
+ /* convert to a Python tupple of long objects */
+ if ((info = PyDict_New()) == NULL) {
+ free(params);
+ return VIR_PY_NONE;
+ }
+ for (i = 0 ; i < nparams ; i++) {
+ PyObject *key, *val;
+
+ switch (params[i].type) {
+ case VIR_DOMAIN_SCHED_FIELD_INT:
+ val = PyInt_FromLong((long)params[i].value.i);
+ break;
+
+ case VIR_DOMAIN_SCHED_FIELD_UINT:
+ val = PyInt_FromLong((long)params[i].value.ui);
+ break;
+
+ case VIR_DOMAIN_SCHED_FIELD_LLONG:
+ val = PyLong_FromLongLong((long long)params[i].value.l);
+ break;
+
+ case VIR_DOMAIN_SCHED_FIELD_ULLONG:
+ val = PyLong_FromLongLong((long long)params[i].value.ul);
+ break;
+
+ case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
+ val = PyFloat_FromDouble((double)params[i].value.d);
+ break;
+
+ case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
+ val = PyBool_FromLong((long)params[i].value.b);
+ break;
+
+ default:
+ free(params);
+ Py_DECREF(info);
+ return VIR_PY_NONE;
+ }
+
+ key = libvirt_constcharPtrWrap(params[i].field);
+ PyDict_SetItem(info, key, val);
+ }
+ free(params);
+ return(info);
+}
+
+static PyObject *
+libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
+ virDomainPtr domain;
+ PyObject *pyobj_domain, *info;
+ char *c_retval;
+ int nparams, i;
+ virSchedParameterPtr params;
+
+ if (!PyArg_ParseTuple(args, (char *)"OO:virDomainSetScedulerParameters",
+ &pyobj_domain, &info))
+ return(NULL);
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ c_retval = virDomainGetSchedulerType(domain, &nparams);
+ if (c_retval == NULL)
+ return VIR_PY_NONE;
+ free(c_retval);
+
+ if ((params = malloc(sizeof(*params)*nparams)) == NULL)
+ return VIR_PY_NONE;
+
+ if (virDomainGetSchedulerParameters(domain, params, &nparams) < 0) {
+ free(params);
+ return VIR_PY_NONE;
+ }
+
+ /* convert to a Python tupple of long objects */
+ for (i = 0 ; i < nparams ; i++) {
+ PyObject *key, *val;
+ key = libvirt_constcharPtrWrap(params[i].field);
+ val = PyDict_GetItem(info, key);
+ Py_DECREF(key);
+
+ if (val == NULL)
+ continue;
+
+ switch (params[i].type) {
+ case VIR_DOMAIN_SCHED_FIELD_INT:
+ params[i].value.i = (int)PyInt_AS_LONG(val);
+ break;
+
+ case VIR_DOMAIN_SCHED_FIELD_UINT:
+ params[i].value.ui = (unsigned int)PyInt_AS_LONG(val);
+ break;
+
+ case VIR_DOMAIN_SCHED_FIELD_LLONG:
+ params[i].value.l = (long long)PyLong_AsLongLong(val);
+ break;
+
+ case VIR_DOMAIN_SCHED_FIELD_ULLONG:
+ params[i].value.ul = (unsigned long long)PyLong_AsLongLong(val);
+ break;
+
+ case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
+ params[i].value.d = (double)PyFloat_AsDouble(val);
+ break;
+
+ case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
+ {
+ /* Hack - Python's definition of Py_True breaks strict
+ * aliasing rules, so can't directly compare :-(
+ */
+ PyObject *hacktrue = PyBool_FromLong(1);
+ params[i].value.b = hacktrue == val ? 1 : 0;
+ Py_DECREF(hacktrue);
+ }
+ break;
+
+ default:
+ free(params);
+ return VIR_PY_NONE;
+ }
+ }
+
+ if (virDomainSetSchedulerParameters(domain, params, nparams) < 0) {
+ free(params);
+ return VIR_PY_NONE;
+ }
+
+ free(params);
+ return VIR_PY_NONE;
+}
+
+static PyObject *
+libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
+ virDomainPtr domain;
+ PyObject *pyobj_domain, *pyretval = NULL, *pycpuinfo = NULL, *pycpumap = NULL;
+ virNodeInfo nodeinfo;
+ virDomainInfo dominfo;
+ virVcpuInfoPtr cpuinfo = NULL;
+ unsigned char *cpumap = NULL;
+ int cpumaplen, i;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetVcpus",
+ &pyobj_domain))
+ return(NULL);
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ if (virNodeGetInfo(virDomainGetConnect(domain), &nodeinfo) != 0)
+ return VIR_PY_NONE;
+
+ if (virDomainGetInfo(domain, &dominfo) != 0)
+ return VIR_PY_NONE;
+
+ if ((cpuinfo = malloc(sizeof(*cpuinfo)*dominfo.nrVirtCpu)) == NULL)
+ return VIR_PY_NONE;
+
+ cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
+ if ((cpumap = malloc(dominfo.nrVirtCpu * cpumaplen)) == NULL)
+ goto cleanup;
+
+ if (virDomainGetVcpus(domain,
+ cpuinfo, dominfo.nrVirtCpu,
+ cpumap, cpumaplen) < 0)
+ goto cleanup;
+
+ /* convert to a Python tupple of long objects */
+ if ((pyretval = PyTuple_New(2)) == NULL)
+ goto cleanup;
+ if ((pycpuinfo = PyList_New(dominfo.nrVirtCpu)) == NULL)
+ goto cleanup;
+ if ((pycpumap = PyList_New(dominfo.nrVirtCpu)) == NULL)
+ goto cleanup;
+
+ for (i = 0 ; i < dominfo.nrVirtCpu ; i++) {
+ PyObject *info = PyTuple_New(4);
+ if (info == NULL)
+ goto cleanup;
+ PyTuple_SetItem(info, 0, PyInt_FromLong((long)cpuinfo[i].number));
+ PyTuple_SetItem(info, 1, PyInt_FromLong((long)cpuinfo[i].state));
+ PyTuple_SetItem(info, 2, PyLong_FromLongLong((long long)cpuinfo[i].cpuTime));
+ PyTuple_SetItem(info, 3, PyInt_FromLong((long)cpuinfo[i].cpu));
+ PyList_SetItem(pycpuinfo, i, info);
+ }
+ for (i = 0 ; i < dominfo.nrVirtCpu ; i++) {
+ PyObject *info = PyTuple_New(VIR_NODEINFO_MAXCPUS(nodeinfo));
+ int j;
+ if (info == NULL)
+ goto cleanup;
+ for (j = 0 ; j < VIR_NODEINFO_MAXCPUS(nodeinfo) ; j++) {
+ PyTuple_SetItem(info, j, PyBool_FromLong(VIR_CPU_USABLE(cpumap, cpumaplen, i, j)));
+ }
+ PyList_SetItem(pycpumap, i, info);
+ }
+ PyTuple_SetItem(pyretval, 0, pycpuinfo);
+ PyTuple_SetItem(pyretval, 1, pycpumap);
+
+ free(cpuinfo);
+ free(cpumap);
+
+ return(pyretval);
+
+ cleanup:
+ free(cpuinfo);
+ free(cpumap);
+ /* NB, Py_DECREF is a badly defined macro, so we require
+ * braces here to avoid 'ambiguous else' warnings from
+ * the compiler.
+ * NB. this comment is true at of time of writing wrt to
+ * at least python2.5.
+ */
+ if (pyretval) { Py_DECREF(pyretval); }
+ if (pycpuinfo) { Py_DECREF(pycpuinfo); }
+ if (pycpumap) { Py_DECREF(pycpumap); }
+ return VIR_PY_NONE;
+}
+
+
+static PyObject *
+libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
+ virDomainPtr domain;
+ PyObject *pyobj_domain, *pycpumap, *truth;
+ virNodeInfo nodeinfo;
+ unsigned char *cpumap;
+ int cpumaplen, i, vcpu;
+
+ if (!PyArg_ParseTuple(args, (char *)"OiO:virDomainPinVcpu",
+ &pyobj_domain, &vcpu, &pycpumap))
+ return(NULL);
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ if (virNodeGetInfo(virDomainGetConnect(domain), &nodeinfo) != 0)
+ return VIR_PY_NONE;
+
+ cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
+ if ((cpumap = malloc(cpumaplen)) == NULL)
+ return VIR_PY_NONE;
+ memset(cpumap, 0, cpumaplen);
+
+ truth = PyBool_FromLong(1);
+ for (i = 0 ; i < VIR_NODEINFO_MAXCPUS(nodeinfo) ; i++) {
+ PyObject *flag = PyTuple_GetItem(pycpumap, i);
+ if (flag == truth)
+ VIR_USE_CPU(cpumap, i);
+ else
+ VIR_UNUSE_CPU(cpumap, i);
+ }
+
+ virDomainPinVcpu(domain, vcpu, cpumap, cpumaplen);
+ Py_DECREF(truth);
+ free(cpumap);
+
+ return VIR_PY_NONE;
+}
+
+
/************************************************************************
* *
* Global error handler at the Python level *
@@ -876,6 +1189,11 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL},
{(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL},
{(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL},
+ {(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType, METH_VARARGS, NULL},
+ {(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters, METH_VARARGS, NULL},
+ {(char *) "virDomainSetSchedulerParameters", libvirt_virDomainSetSchedulerParameters, METH_VARARGS, NULL},
+ {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
+ {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};
--
|=- 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 -=|
16 years, 11 months