[libvirt-users] virDomainGetInfo() returns wrong domain state

Panday Ritesh Sharma (rpanday) rpanday at cisco.com
Tue Sep 24 14:51:35 UTC 2013


Hi Team,
I have written below code to get the VM state at run time. I found, though the VM is in shut-off state, when I use the function virDomainGetInfo();  I get state as running. Could you please let me know what wrong I am doing. To know the actual VM state I used 'virsh list' and it clearly shows the VM is in shut-off state. Please find the log and code snippet below.

Log from virsh:
=================
[host:~]$ virsh list  --all
Id    Name                           State
----------------------------------------------------
1     calvados                       running
2     LCXR                           running
3     default-sdr--1                 running
-     test--2                        shut off

Out put:
=========
04.03.06.698923264:INFO: vm_libvirt_state_to_vmm_state: state returned is 1

Note : Here 1 is actually running.

Code snippet:
===============
enum cidl_vmm_vm_state
vm_libvirt_state_to_vmm_state(unsigned char libvirt_state)
{
    enum cidl_vmm_vm_state state;
    INFO("%s: state returned is %u\n",__FUNCTION__, libvirt_state); <<<<<<<<<<<<<<<<<<
    if (libvirt_state == VIR_DOMAIN_RUNNING) {
        state = cidl_vm_state_running;
    } else if ((libvirt_state == VIR_DOMAIN_PAUSED) ||
               (libvirt_state == VIR_DOMAIN_BLOCKED)) {
        state = cidl_vm_state_paused;
    } else if (libvirt_state == VIR_DOMAIN_SHUTOFF) {
        state = cidl_vm_state_defined;
    } else {
        state = cidl_vm_state_not_defined;
    }
    return state;
}

           virDomainInfo res_util;
            virDomainPtr dom = virDomainLookupByName(virt,
                                                     private_names[vm_idx]);
            res = virDomainGetInfo(dom, &res_util);
            vminfo[vm_idx].vm_state =
                  vm_libvirt_state_to_vmm_state(res_util.state);



Regards
Ritesh Sharma
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20130924/db320e3e/attachment.htm>


More information about the libvirt-users mailing list