[libvirt-users] domain reinitalization detection

Michal Privoznik mprivozn at redhat.com
Mon Mar 6 13:38:21 UTC 2017


On 06.03.2017 14:14, Matczak, KrzysztofX wrote:
> Hello
> 
> I'm trying to find out how to detect if domain was destroyed and brought up between two time moments,  let's call it reads. 
> So far the best approach I could find is to compare domain ID from previous and current read. 
>  And this is my first question : is that reliable solution ? Or do you know any better  ?

Listen to the events. If domain is destroyed/started libvirt fires up an
event. The domain ID is not necessarily unique. For instance:

a) start a domain and assume it's the first one started. It will have ID=1.
b) destroy it.
c) restart libvirtd.
d) start the domain again - it will have ID=1.

This applies to qemu driver, other drivers might have different meaning
for domain IDs - e.g. LXC driver reports PID of the container's init in
which case you can make no assumptions about it.

> 
> And related question is how to  resolve virDomainPtr into domain ID ?

virDomainGetID().

> The only verified  way  of getting domain ID I know is  to memorize it's UUID, then  call virConnectListDomains , then iterate over all returned domain IDs and resolve each one's pointer  using virDomainLookupByID , then  get  UUID  by virDomainGetUUIDString  get domain ID of matching UUID's .  
> It seems too complex  and I  expect noticeable performance overhead, so looking for something lighter.  
> 
> I'm trying to get current domain ID using  API function : 
> 
> char *    virDomainGetMetadata (virDomainPtr domain,  int type,  const char * uri, unsigned int flags)
> 
> I'm  not sure it's  relevant  function, since domain ID is contained not in metadata subsection but in opening <domain> markup. 
> In fact  I wasn't even able to get any data using that function call since I don't know how to construct valid URI. Do you know any doc or examples explaining that ?  

Documentation might come handy:

http://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMetadata
http://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMetadata

or just look into our test suite:

http://libvirt.org/git/?p=libvirt.git;a=blob;f=tests/metadatatest.c;h=55dc841254bcfda0742d22580723bf4acac172b4;hb=HEAD

Michal




More information about the libvirt-users mailing list