[Libvir] Perl API for using libvirt
by Daniel P. Berrange
Hi Folks,
I had a couple of hours spare, so I put together a set of Perl bindings
for libvirt. I'm currently calling the module Sys::Virt which seems to
be the most appropriate location in the CPAN namespace, but I'm open to
suggestions if people think that sucks. I've currently got near 100%
coverage of the C APIs, but not exposed all the static constants yet.
There are a couple of trivial example programs illustrating use of the
API for extracting info about domains.=20
For now you can grab a snapshot of the source for the binding using=20
Mercurial from the URL:
http://hg.berrange.com/libraries/sys-virt
When I've tested it more completely I'll upload it to CPAN
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 -=|
18 years, 7 months
[Libvir] Request for additional entry points
by Jim Fehlig
As discussed on the xen-cim call on 3/31, the Xen CIM provider needs
some additional entry points in libvirt. I would like to open a
discussion about adding the following entry points to libvirt.
virDomainSetConfig(virConnectPtr conn, const char *xmlDesc)
Stores the domU config data in xenstore. The domU is not running yet
but enumerating domains would return the config for the domain as well
as any running domains. This would support the notion of a defined but
inactive virtual machine. Daniel noted that the config could be cached
in libvirt, preventing (to some degree) modifying the config out-of-band
prior to activating the domain. Note that the current
virConnectListDomains() implies enumerating only running domains since a
list of domain IDs is returned. Perhaps virConnectListDomains() will
have to be expanded to include defined domains or another entry point to
enumerate defined domains.
Related would be activating a defined domain. Would clients get the
domain config (via virDomainGetXMLDesc()) and subsequently pass it to
virDomainCreateLinux() or another entry point to create a defined domain?
virDomainDeleteConfig(virConnectPtr conn, const char *name)
Removed domU config from xenstore (or cache). DomU no longer "exists".
What if domain is active upon invocation?
virDomainSetCurrentMemory(virDomainPtr domain, unsigned long memory)
Adjust the current memory usage for a domain.
virDomainReboot(virDomainPtr domain)
Reboot the domain.
virDomainMigrate(virDomainPtr domain, const char *host)
?? Not sure what can of worms might be opened by this one :-).
Thoughts?
BTW, I can certainly help with the effort if an agreement is reached on
adding this functionality.
Regards,
Jim
18 years, 7 months
[Libvir] autogen.sh error
by Ronald Aigner
Hi all,
I downloaded libvirt from CVS and tried to run autogen.sh which stops
with the following error message:
configure: error: Xen store library not found
What else do I need?
How do I implement support for another hypervisor? Where do I have to
turn which screws?
Thanks, Ron.
18 years, 7 months
[Libvir] Patch to make reading of HTTP response more efficient
by Daniel P. Berrange
When processing the header of HTTP responses from Xend, libvirt currently
reads data a single byte at a time. Since its using lowlevel UNIX read()
function there is no buffering, which results in a large number of system
calls. The attached patch re-factors the code so that it reads data in
4k chunks whenever possible. Since most rsponses are < 4k in size processing
the response now only takes two read() syscalls, rather than several hundred.
Of course most (90%) of the CPU overhead is still on the Xend/XenStored
end of the channel, but that's out of our control until the XML-RPC API
comes along.
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 -=|
18 years, 8 months
[Libvir] unchecked `malloc' calls
by Jim Meyering
Hello,
In browsing through the code, I noticed that there are many
places in which the code doesn't check for malloc returning NULL.
E.g.,
./virsh.c: ids = malloc(sizeof(int) * maxid);
./virsh.c- virConnectListDomains(ctl->conn, &ids[0], maxid);
./virsh.c: *res = malloc(sz + 1);
./virsh.c- memcpy(*res, tkstr, sz);
./virsh.c: res = malloc(strlen(name) + 3);
./virsh.c- sprintf(res, "--%s", name);
./xmlrpc.c: buf = malloc(sizeof(*buf));
./xmlrpc.c- buf->size = 1024;
./xmlrpc.c: xmlRpcValueDictElementPtr ret = malloc(sizeof(*ret));
./xmlrpc.c- xmlNodePtr cur;
./xmlrpc.c-
./xmlrpc.c- memset(ret, 0, sizeof(*ret));
At first, seeing so many, I thought there must be a wrapper
that handles the case of a NULL return value. But there are
many places where the code *does* check for NULL.
This may be a clue. Maybe it's planned...
./libvirt.c: * TODO:
...
./libvirt.c: * - memory wrappers for malloc/free ?
Jim
18 years, 8 months
[Libvir] RFC: requesting APIs for host physical resource discovery
by Daniel P. Berrange
The current libvirt APIs allow the host's physical resources to be split up
and allocated to guest domains, however, there is no way to discover what
the available host resources actually are. Thus I would like to suggest the
inclusion of new APIs to enable host resource discovery. As a starting point
I'd like to be able to query the following information:
* Number of physical CPUs - ability to enumerate the CPUs in the host,
both those currently present, and theoretical maximum (to take account
of hotplug).
* Amount of RAM - actual physical RAM present, and that available for
guest usage (eg discounting that reserved by a hypervisor or equiv)
* CPU relationship - ie ability to distinguish between CPUs which
are hyperthread siblings, on same core, or on separate sockets
Alonside these basic queries it would be desirable to add a further resource
resource management API to allow for setting of a guest domain's CPU affinity.
ie ability control what CPUs the VMM is allowed to schedule a domain on.
Once this first basic set of caapbilties for resource discovery are provided
for, then I believe it will be neccessary to provide some more advanced
queries, in particular:
* NUMA topology - ability to enumerate NUMA nodes, the CPUs associated
with each node & the RAM range mapped to that node
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 -=|
18 years, 8 months
[Libvir] python/libvir.html example needs adjustment
by Jim Meyering
Hello,
Trying a variant of this example from python/libvir.html:
import libvirt
import sys
conn = libvirt.openReadOnly(None)
if conn == None:
print 'Failed to open connection to the hypervisor'
sys.exit(1)
dom0 = conn.lookupByName("Domain-0")
if dom0 == None:
print 'Failed to find the main domain'
sys.exit(1)
print "Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType())
print dom0.info()
I found that conn.lookupByName throws an exception when the specified
name is not found. If the example is just out of date, it should use
try:/except: instead of comparing dom0 to None, shouldn't it?
You can demonstrate it like this:
$ python -c 'import libvirt; libvirt.openReadOnly(None).lookupByName("x")'
libvir: Xen Daemon error : GET operation failed: No such domain x
Traceback (most recent call last):
File "<string>", line 1, in ?
File "/usr/lib/python2.4/site-packages/libvirt.py", line 213, in lookupByName
if ret is None:raise libvirtError('virDomainLookupByName() failed')
libvirt.libvirtError: virDomainLookupByName() failed
[Exit 1]
Jim
18 years, 8 months
[Libvir] use gcc's printf __attribute__
by Jim Meyering
Hello,
I noticed that there are a few printf-like functions here,
but that they don't benefit from gcc's format-string vs. arg-type
checking. Here's a patch to enable that:
However, to make it portable to non-gcc systems, this block
of cpp directives needs to go somewhere (maybe libvirt.h?)
so it'll be used from both files.
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
# define __attribute__(Spec) /* empty */
# endif
/* The __-protected variants of `format' and `printf' attributes
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
# define __format__ format
# define __printf__ printf
# endif
#endif
2006-03-25 Jim Meyering <jim(a)meyering.net>
* src/virsh.c (vshPrint, vshError): Add gcc's __printf__ attribute.
* src/xml.h (virBufferVSprintf): Likewise.
Index: src/xml.h
===================================================================
RCS file: /data/cvs/libvirt/src/xml.h,v
retrieving revision 1.3
diff -u -p -r1.3 xml.h
--- src/xml.h 15 Mar 2006 12:13:25 -0000 1.3
+++ src/xml.h 25 Mar 2006 10:56:27 -0000
@@ -25,7 +25,8 @@ extern "C" {
};
int virBufferAdd(virBufferPtr buf, const char *str, int len);
- int virBufferVSprintf(virBufferPtr buf, const char *format, ...);
+ int virBufferVSprintf(virBufferPtr buf, const char *format, ...)
+ __attribute__ ((__format__ (__printf__, 2, 3)));
char *virDomainParseXMLDesc(const char *xmldesc, char **name);
#ifdef __cplusplus
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.21
diff -u -p -r1.21 virsh.c
--- src/virsh.c 15 Mar 2006 12:13:25 -0000 1.21
+++ src/virsh.c 25 Mar 2006 10:56:28 -0000
@@ -177,8 +177,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);
@@ -198,8 +198,9 @@ static virDomainPtr vshCommandOptDomain(
const char *optname, char **name);
-static void vshPrint(vshControl * ctl, vshOutType out, const char *format,
- ...);
+static void vshPrint(vshControl * ctl, vshOutType out, const char *format, ...)
+ __attribute__ ((__format__ (__printf__, 3, 4)));
+ ;
static const char *vshDomainStateToString(int state);
18 years, 8 months
[Libvir] Patch for include file syntax
by Daniel P. Berrange
When doing an out-of-tree build of code which uses virterror.h,
one gets a build failure, because when deployed virterror.h lives
in subdir of the include directory rather than the top level
In file included from Virt.xs:25:
/usr/include/libvirt/virterror.h:17:21: error: libvirt.h: No such file or directory
In file included from Virt.xs:25:
/usr/include/libvirt/virterror.h:62: error: expected specifier-qualifier-list before âvirConnectPtrâ
/usr/include/libvirt/virterror.h:122: error: expected â)â before âconnâ
/usr/include/libvirt/virterror.h:123: error: expected â)â before âconnâ
/usr/include/libvirt/virterror.h:129: error: expected â)â before âconnâ
/usr/include/libvirt/virterror.h:132: error: expected â)â before âconnâ
This is fixable by making virterror.h use "..." instead of <...> to
include libvirt.h. Attaching a patch to fix this
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 -=|
18 years, 8 months
[Libvir] Patch for pkg-config file cflags
by Daniel P. Berrange
The libvirt.pc.in file has an empty field for the cflags variable, so
if you install libvirt into any prefix which is not in the compiler's
default include file search path the header files won't be found when
compiling applications. Attching a patch which corrects the pkg-config
file for libvirt
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 -=|
18 years, 8 months