Matczak, KrzysztofX
2017-Mar-06 13:14 UTC
[libvirt-users] domain reinitalization detection
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 ? And related question is how to resolve virDomainPtr into domain ID ? 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 ? Any help appreciated Krzysztof -------------------------------------------------------------- Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
Michal Privoznik
2017-Mar-06 13:38 UTC
Re: [libvirt-users] domain reinitalization detection
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
Matczak, KrzysztofX
2017-Mar-06 13:51 UTC
Re: [libvirt-users] domain reinitalization detection
> Listen to the eventsI guess that would require running my own polling thread, right ? I wanted to avoid that ... Thanks for help 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 -------------------------------------------------------------- Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.