[libvirt] Using Xen config files

I am trying to programmatically start Xen guest VMs (HVM) with libvirt (on Fedora Core 8) and I'm having some trouble with it. I've included my code below. Essentially, the domain seems to get created correctly but it doesn't seem to run. I don't receive any error messages from the libvirt functions but the VM does not get any CPU time (as shown with "xm list"). [root@grape ~]$ xm list Name ID Mem VCPUs State Time(s) Domain-0 0 1462 2 r----- 1313.5 fc8.conf 7 128 1 ------ 0.0 Can someone explain what I'm doing wrong here? I've tried to get this working with linux and windows guests with the same results. I've seen references on this mailing list to libvirt's ability to handle Xen configuration files but I haven't seen anything in the API documentation or public header files that refer to it. Is there a public interface to specifying a configuration file? Thanks -matthew CODE: #include <stdio.h> #include <libvirt/libvirt.h> #include <libvirt/virterror.h> //"<!--<mac address='00:16:3e:5d:c7:9e'/>-->" //"<graphics type='vnc' port='5904'/>" const char* fedora = "<domain type='xen'>" "<name>fc8.conf</name>" "<os>" "<type>hvm</type>" "<loader>/usr/lib/xen/boot/hvmloader</loader>" "<boot dev='hd'/>" "</os>" "<memory>1024</memory>" "<vcpu>1</vcpu>" "<on_poweroff>destroy</on_poweroff>" "<on_reboot>restart</on_reboot>" "<on_crash>restart</on_crash>" "<features>" "<pae/>" "<acpi/>" "<apic/>" "</features>" "<clock sync=\"localtime\"/>" "<devices>" "<emulator>/usr/lib/xen/bin/qemu-dm</emulator>" "<interface type='bridge'>" "<source bridge='xenbr0'/>" "<script path='vif-bridge'/>" "</interface>" "<disk type='block'>" "<source dev='/dev/vgvms/fc8'/>" "<target dev='hda'/>" "</disk>" "<disk type='block' device='cdrom'>" "<source dev='/dev/cdrom'/>" "<target dev='hdc'/>" "<readonly/>" "</disk>" "<graphics type='vnc'/>" "</devices>" "</domain>"; int main (int argc, char** argv) { virConnectPtr con; /* connection to the Xen hypervisor */ virDomainPtr domain; virInitialize(); con = virConnectOpen ("xen:///"); if (!con) { virErrorPtr err = virGetLastError (); printf ("virConnectOpen failed: %s\n", err->message); return -1; } domain = virDomainDefineXML (con, fedora); if (!domain) { virErrorPtr err = virGetLastError (); printf ("virDomainDefineXML failed: %s\n", err->message); } else { if (virDomainCreate (domain) < 0) { virErrorPtr err = virGetLastError (); printf ("virDomainCreate failed: %s\n", err->message); } else { virDomainInfo info = {0}; virDomainGetInfo (domain, &info); printf ("state = %d\n", info.state); } } virConnectClose (con); return 0; }

On Wed, Aug 20, 2008 at 08:35:46AM -0400, Matthew Donovan wrote:
I am trying to programmatically start Xen guest VMs (HVM) with libvirt (on Fedora Core 8) and I'm having some trouble with it. I've included my code below. Essentially, the domain seems to get created correctly but it doesn't seem to run.
I don't receive any error messages from the libvirt functions but the VM does not get any CPU time (as shown with "xm list").
[root@grape ~]$ xm list Name ID Mem VCPUs State Time(s) Domain-0 0 1462 2 r----- 1313.5 fc8.conf 7 128 1 ------ 0.0
Can someone explain what I'm doing wrong here? I've tried to get this working with linux and windows guests with the same results.
That's really strange. Your program looks correct to me (but see my comment about error handling below). One thing you can do is to run your program after first setting the environment variable LIBVIRT_DEBUG=1 which will cause all calls to libvirt to be printed out. Just to make sure you are actually calling the functions that you think you are calling.
I've seen references on this mailing list to libvirt's ability to handle Xen configuration files but I haven't seen anything in the API documentation or public header files that refer to it. Is there a public interface to specifying a configuration file?
No there isn't. This ability refers to old versions of Xen which used /etc/xen. We have a driver that can parse files from here and present those as inactive ("defined" but not running) domains, eg. when you do "virsh list". For all other uses, use the libvirt XML configuration format. The advantage is that it will keep working with other types of virtualization.
domain = virDomainDefineXML (con, fedora); if (!domain) { virErrorPtr err = virGetLastError (); printf ("virDomainDefineXML failed: %s\n", err->message);
By the way, this error reporting is wrong. Confusingly there are two levels of errors stored by virterror, a global error and a per-connection error. The global error is only used where you don't have a virConnectPtr object (almost the only time is just after virConnectOpen fails, when conn == NULL). The rest of the time you should use virConnGetLastError: http://libvirt.org/html/libvirt-virterror.html#virConnGetLastError Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
participants (2)
-
Matthew Donovan
-
Richard W.M. Jones