possible bug in virDomainLookupByID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
thoughts?

Thanks,
bryan

PS... This problem is seen in XenAccess.  Thanks to Daniele Sgandurra for
bringing it to my attention.
#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);

error_exit:
    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;
    }
    free(xml);
    xml = get_xml_info(1);
    if (!xml){
        printf("Failed on second try\n");
        return 0;
    }
    free(xml);

    return 1;
}

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]