[Libvir] possible bug in virDomainLookupByID

Bryan D. Payne bryan at thepaynes.cc
Tue Jul 18 15:48:29 UTC 2006

I'm experiencing an odd problem in virDomainLookupByID when using 0.1.3
that does not exist when using 0.1.1.  Perhaps this is a side effect of
switching the backend connection?  I'm curious is anyone else has seen
this and/or if you have any suggestions for fixing it.

The attached code generates the problem that I'm seeing.  Specifically,
after upgrading to 0.1.3, calling virDomainLookupByID twice results in a
failure on the second call.  This behavior was not seen in 0.1.1.  Any


PS... This problem is seen in XenAccess.  Thanks to Daniele Sgandurra for
bringing it to my attention.
-------------- next part --------------
#include <stdio.h>
#include <string.h>
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <libxml/parser.h>
#include <libxml/tree.h>

char *get_xml_info (int id)
    virConnectPtr conn = NULL;
    virDomainPtr dom = NULL;
    char *xml_data = NULL;

    /* NULL means connect to local Xen hypervisor */
    conn = virConnectOpenReadOnly(NULL);
    if (NULL == conn) {
        printf("ERROR: Failed to connect to hypervisor\n");
        goto error_exit;

    /* Find the domain of the given id */
    dom = virDomainLookupByID(conn, id);
    if (NULL == dom) {
        virErrorPtr error = virConnGetLastError(conn);
        printf("(%d) %s\n", error->code, error->message);
        printf("ERROR: Failed to find Domain %d\n", id);
        goto error_exit;

    xml_data = virDomainGetXMLDesc(dom, 0);

    if (NULL!= dom) virDomainFree(dom);
    if (NULL!= conn) virConnectClose(conn);

    return xml_data;

int main ()
    char *xml = NULL;
    xml = get_xml_info(1);
    if (!xml){
        printf("Failed on first try\n");
        return 0;
    xml = get_xml_info(1);
    if (!xml){
        printf("Failed on second try\n");
        return 0;

    return 1;

More information about the libvir-list mailing list