Yes, I am sure because other information pulled are correct. And the same way 
we have used libvirt APIs to extract other informations at different places.

My question is if VM is in shut-off state does it mean running ? IF not, what 
is the correct state for this VM. I am wondering why the state is 'unsigned 
char' in virDomainGetInfo, why it could not be 'enum'  as it is returning enums 
only.



Regards
Ritesh Sharma

-----Original Message-----
From: Michal Privoznik [mailto:mpriv...@redhat.com] 
Sent: Thursday, September 26, 2013 12:54 PM
To: Panday Ritesh Sharma (rpanday)
Cc: libvir-list@redhat.com; libvirt-us...@redhat.com; Vinay Shankarkumar 
(vinays); q-se-dev(mailer list); Basavaraj Bendigeri (bbendige)
Subject: Re: [libvirt] virDomainGetInfo() returns wrong domain state

On 24.09.2013 16:51, Panday Ritesh Sharma (rpanday) wrote:
>  
> 
> 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;
> 
> }

While this part ^^^ looks okay, the part below looks suspicious. I mean not 
from API perspective, but from data perspective.
> 
>  
> 
>            virDomainInfo res_util;
> 
>             virDomainPtr dom = virDomainLookupByName(virt,
> 
>                                                      
> private_names[vm_idx]);

Are you sure you're passing the correct name here? That's the only possible 
source of the error here.

> 
>             res = virDomainGetInfo(dom, &res_util);
> 
>             vminfo[vm_idx].vm_state =
> 
>                   vm_libvirt_state_to_vmm_state(res_util.state);
> 
>  

Michal


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to